package com.jucai.pppeiyouclient.view.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.signature.StringSignature;
import com.google.gson.Gson;
import com.jucai.pppeiyouclient.MainActivity;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.BaseActivity;
import com.jucai.pppeiyouclient.bean.AccompanyBean;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.ActivityCollector;
import com.jucai.pppeiyouclient.utils.AnimUtil;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.utils.LoginUtils;
import com.jucai.pppeiyouclient.utils.SharedPreferencesUtil;

import org.json.JSONObject;

import java.util.Date;
import java.util.HashMap;

public class AccountSafeActivity extends BaseActivity {
    private static String TAG = "AccountSafeActivity";
    private TextView safePhone, safeNameVerified, safePassSet;
    private int memberApplyStatus;//审核状态 0 未审核 1通过 -1未通过 -2 未提交
    private String memberApplyStatusText, iDcardInhand, iDcardFront, iDcardBack, realName, idCardNumber, realAddress,memberApplyVerifyDetails;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_account_safe);

        ((TextView) findViewById(R.id.common_title_text)).setText("账号与安全");
        safePhone = (TextView) findViewById(R.id.safe_phone);
        safeNameVerified = (TextView) findViewById(R.id.safe_name_verified);
        safePassSet = (TextView) findViewById(R.id.safe_pass_set);
    }

    @Override
    protected void initData() {
        safePhone.setText(SharedPreferencesUtil.getStringPreference(AccountSafeActivity.this, "PREFERENCE", "phone_number", ""));
       /* if (SharedPreferencesUtil.getIntPreference(AccountSafeActivity.this, "PREFERENCE", "member_status", 0) == 1) {
            safeNameVerified.setText("已认证");
        } else {
            safeNameVerified.setText("未认证");
        }*/
        safeNameVerified.setEnabled(false);

        getInfo();
    }

    private void getInfo() {
        HashMap<String, String> param = new HashMap<>();
        param.put("service", "Accompany_Apply.getLastInfo");
        CommonRequestNetData.getJsonObjectData(AccountSafeActivity.this, param, true, new CommonRequestNetData.JsonObjectCallBack() {
            @Override
            public void parseJsonObject(JSONObject jsonObject) throws Exception {
                LogUtils.e(TAG + "jsObj = " + jsonObject.toString());
                memberApplyStatus = Integer.parseInt(jsonObject.getString("member_apply_status"));
                memberApplyStatusText = jsonObject.has("member_apply_status_text") ? jsonObject.getString("member_apply_status_text") : "";

                iDcardInhand = jsonObject.has("IDcard_inhand") ? jsonObject.getString("IDcard_inhand") : "";
                iDcardFront = jsonObject.has("IDcard_front") ? jsonObject.getString("IDcard_front") : "";
                iDcardBack = jsonObject.has("IDcard_back") ? jsonObject.getString("IDcard_back") : "";

                realName = jsonObject.has("member_realname") ? jsonObject.getString("member_realname") : "";
                idCardNumber = jsonObject.has("member_IDcardno") ? jsonObject.getString("member_IDcardno") : "";
                realAddress = jsonObject.has("member_area_info") ? jsonObject.getString("member_area_info") : "";

                memberApplyVerifyDetails = jsonObject.has("member_apply_verify_details") ? jsonObject.getString("member_apply_verify_details") : "";

                SharedPreferencesUtil.saveIntPreference(AccountSafeActivity.this, "PREFERENCE", "member_status", memberApplyStatus);
                safeNameVerified.setText(memberApplyStatusText);
                safeNameVerified.setEnabled(true);
            }

        });
    }

    @Override
    protected void loadNetData() {

    }

    @Override
    protected void setListener() {
        findViewById(R.id.common_back).setOnClickListener(this);
        findViewById(R.id.common_home_back).setOnClickListener(this);
        /*if (SharedPreferencesUtil.getIntPreference(AccountSafeActivity.this, "PREFERENCE", "member_status", 0) == 1) {
            safeNameVerified.setOnClickListener(null);
        } else {
            safeNameVerified.setOnClickListener(this);
        }*/
        safeNameVerified.setOnClickListener(this);
        safePassSet.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                ActivityCollector.removeActivity(this);
                break;

            case R.id.common_home_back:
                startActivity(new Intent(AccountSafeActivity.this, MainActivity.class));
                ActivityCollector.removeActivity(this);
                break;

            case R.id.safe_name_verified:
//                startActivity(new Intent(AccountSafeActivity.this, RegisterThirdStepActivity.class));
                /*SharedPreferencesUtil.saveStringPreference(AccountSafeActivity.this, "PREFERENCE", "password", "for_main_not_pass");
                RegisterThirdStepActivity.startRealName(AccountSafeActivity.this, 1);*/
                Intent intent = new Intent(AccountSafeActivity.this, RegisterThirdStepActivity.class);
                intent.putExtra("status", memberApplyStatus);
                intent.putExtra("status_name", memberApplyStatusText);

                intent.putExtra("iDcardInhand", iDcardInhand);
                intent.putExtra("iDcardFront", iDcardFront);
                intent.putExtra("iDcardBack", iDcardBack);

                intent.putExtra("realName", realName);
                intent.putExtra("realAddress", realAddress);
                intent.putExtra("idCardNumber", idCardNumber);

                intent.putExtra("memberApplyVerifyDetails", memberApplyVerifyDetails);

                intent.putExtra("type", 1);
                startActivity(intent);
//                startActivity(new Intent(AccountSafeActivity.this, RegisterInfoReviewingActivity.class));
                break;

            case R.id.safe_pass_set:
                startActivity(new Intent(AccountSafeActivity.this, PassChangeActivity.class));
                break;

            default:
                break;
        }
    }
}
